package com.iflytek.uoamp.agent.monitor.internet;

import org.apache.log4j.Logger;

//import jpcap.JpcapCaptor;
//import jpcap.NetworkInterface;

/**
 * Created by Administrator on 2017/2/21.
 */
public class GetInterNetSpeedThread implements Runnable{
    private static volatile GetInterNetSpeedThread instance;

    private String ip = null;

    private GetInterNetSpeedThread(String ip){
    	this.ip = ip;
    }

    public static GetInterNetSpeedThread getInstance(String ip) {
        if (instance == null) {
            synchronized (GetInterNetSpeedThread.class) {
                if (instance == null) {
                    instance = new GetInterNetSpeedThread(ip);
                }
            }
        }
        return instance;
    }

    public static void setInstance(GetInterNetSpeedThread instance) {
    	GetInterNetSpeedThread.instance = instance;
    }

	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}


    @Override
    public void run() {
        Logger.getRootLogger().info("GetInterNetSpeedThread Start!");
		new Thread(InterNetSpeed.getInstance(), "InternetSpeed thread").start();
		// 获得网络设备列表
//		NetworkInterface[] devices = JpcapCaptor.getDeviceList();
//		NetworkInterface ni = null;
//		// String str = "/172.16.20.10";
//		JpcapCaptor jpcap;
//		for (int i = 0; i < devices.length; i++) {
//			ni = devices[i];
//			for (int j = 0; j < ni.addresses.length; j++) {
//				// 一个网卡可能有多个地址,获得本机IP地址
//				if (ni.addresses[j].address.toString().equals(ip)) {
//					try {
//						jpcap = JpcapCaptor.openDevice(ni, 65535, true, 2000);
//						jpcap.loopPacket(-1, new getPacket(ip));
//					} catch (IOException e) {
//						e.printStackTrace();
//					}
//				}
//			}
//		}
	}



}
